flour >= 4 true sugar >= 2 false
Here is part of the program again:
// check that there are enough of both ingredients
if ( flour >= 4 && sugar >= 2 )
System.out.println("Enough for cookies!" );
else
System.out.println("sorry...." );
For you to have enough ingredients, both relational expressions must be true. This is the role of the && (and-operator) between the two relational expressions. The && requires that both
flour >= 4
and
sugar >= 2
are true before the entire expression is true. The entire question must be true in order for the true branch to execute.
The and
operator && is a
logical operator.
A logical logical operator looks at true and
false values
and combines them into a single true or false.